package cn.iocoder.yudao.module.vote.dal.mysql.fielddynamicsconfig;

import java.util.*;

import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX;
import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX;
import cn.iocoder.yudao.module.vote.dal.dataobject.fielddynamicsconfig.FieldDynamicsConfigDO;
import org.apache.ibatis.annotations.Mapper;
import cn.iocoder.yudao.module.vote.controller.admin.fielddynamicsconfig.vo.*;

/**
 * 表动态配置字段展示 Mapper
 *
 * @author moving
 */
@Mapper
public interface FieldDynamicsConfigMapper extends BaseMapperX<FieldDynamicsConfigDO> {

    default PageResult<FieldDynamicsConfigDO> selectPage(FieldDynamicsConfigPageReqVO reqVO) {
        return selectPage(reqVO, new LambdaQueryWrapperX<FieldDynamicsConfigDO>()
                .eqIfPresent(FieldDynamicsConfigDO::getTitle, reqVO.getTitle())
                .likeIfPresent(FieldDynamicsConfigDO::getTableName, reqVO.getTableName())
                .eqIfPresent(FieldDynamicsConfigDO::getFieldList, reqVO.getFieldList())
                .eqIfPresent(FieldDynamicsConfigDO::getShowFieldList, reqVO.getShowFeldList())
                .eqIfPresent(FieldDynamicsConfigDO::getOrderList, reqVO.getOrderList())
                .betweenIfPresent(FieldDynamicsConfigDO::getCreateTime, reqVO.getBeginCreateTime(), reqVO.getEndCreateTime())
                .orderByDesc(FieldDynamicsConfigDO::getId));
    }

    default List<FieldDynamicsConfigDO> selectList(FieldDynamicsConfigExportReqVO reqVO) {
        return selectList(new LambdaQueryWrapperX<FieldDynamicsConfigDO>()
                .eqIfPresent(FieldDynamicsConfigDO::getTitle, reqVO.getTitle())
                .likeIfPresent(FieldDynamicsConfigDO::getTableName, reqVO.getTableName())
                .eqIfPresent(FieldDynamicsConfigDO::getFieldList, reqVO.getFieldList())
                .eqIfPresent(FieldDynamicsConfigDO::getShowFieldList, reqVO.getShowFeldList())
                .eqIfPresent(FieldDynamicsConfigDO::getOrderList, reqVO.getOrderList())
                .betweenIfPresent(FieldDynamicsConfigDO::getCreateTime, reqVO.getBeginCreateTime(), reqVO.getEndCreateTime())
                .orderByDesc(FieldDynamicsConfigDO::getId));
    }

    default FieldDynamicsConfigDO getByTableName(String tableName){
        return selectOne(new LambdaQueryWrapperX<FieldDynamicsConfigDO>()
                .eq(FieldDynamicsConfigDO::getTableName, tableName)
                .last("limit 1"));
    }

}
